package com.zendesk_helpcenter

import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import zendesk.core.JwtIdentity
import zendesk.core.Zendesk
import zendesk.support.Support
import zendesk.support.requestlist.RequestListActivity
import zendesk.core.AnonymousIdentity

class FlutterZendeskCommonMethod (private val plugin: FlutterZendeskPlugin, private val channel: MethodChannel) {

    companion object {
        const val tag = "[ZendeskMessaging]"
        const val initializeSuccess: String = "initialize_success"

    }

    fun initialize(
        urlString: String,
        appId: String,
        clientId: String,
        jwt: String?,
        name: String?,
        email: String?,
    ) {
        Zendesk.INSTANCE.init( plugin.activity!!, urlString, appId, clientId)
        if(jwt != null){
            Zendesk.INSTANCE.setIdentity(JwtIdentity(jwt))
        }else{
            val identity = AnonymousIdentity.Builder()
                .withNameIdentifier(name) // name is optional
                .withEmailIdentifier(email) // email is optional
                .build();
            Zendesk.INSTANCE.setIdentity(identity)
        }
        Support.INSTANCE.init(Zendesk.INSTANCE)
        plugin.isInitialize = true
        channel.invokeMethod(initializeSuccess, null)
    }


    fun showRequestList(call: MethodCall) {
//        val x =  RequestActivity.builder().withCustomFields(Arrays.asList(osPlatForm)).config()
        RequestListActivity.builder().show(plugin.activity!!)
    }


}